package cn.chy.com.springbootdemo2.controller;

import cn.chy.com.springbootdemo2.pojo.Department;
import cn.chy.com.springbootdemo2.pojo.UserInfo;
import cn.chy.com.springbootdemo2.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: TODO
 * @author: 颜景琦
 * @date: 2021年10月22日 14:26
 */
@RestController
@CrossOrigin
@Api(description = "部门控制层1")
public class DepartmentController {

    @Resource
    private DepartmentService departmentService;

    @PostMapping("/doAdd")
    public Map<String, Object> insertOne(@RequestBody Department department) {
        boolean save = departmentService.save(department);

        Map<String, Object> map = new HashMap<>();

        map.put("result", save);
        return map;
    }


    @PostMapping("/doEdit")
    public Map<String, Object> updateOne(@RequestBody Department department) {
        boolean save = departmentService.updateById(department);

        Map<String, Object> map = new HashMap<>();

        map.put("result", save);
        return map;
    }


    // 手机号验证
    @PostMapping("/patterPhone")
    public Map<String, Object> patterOne(@Validated @RequestBody UserInfo userInfo) {

        return null;
    }


    @PostMapping("/delete/{id}")
    public Map<String, Object> delete(@PathVariable String id) {
        boolean res = departmentService.removeById(id);

        Map<String, Object> map = new HashMap<>();

        map.put("result", res);
        return map;
    }


    @GetMapping("/getAll")
    public Object getAll() {


        return departmentService.list();
    }

}
